﻿package mortal.game.view.heroArena.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.cd.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.control.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.treasureHunt.renderer.*;
    import mortal.game.view.heroArena.util.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.game.view.vip.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class HeroArenaEnterWin extends ActivityBaseWindow
    {
        private var _vipOpenTips:VipOpenTipsPanel;
        private var _rewardItemList:GTileList;
        private var _arenaShop:GButton;
        private var _transferBtn:GLoadingButton;
        private var _secTimeData:SecTimerViewData;
        private static var _instance:HeroArenaEnterWin;

        public function HeroArenaEnterWin(param1:ILayer = null, param2:String = "", param3:String = "")
        {
            setSize(696, 412);
            super(param1, ImagesConst.HeroArenaEnterTitle, ImagesConst.HeroArenaEnterBg);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41544), 269 - 10 - 41, 82, 302, 25, this, GlobalStyle.textFormatLv.setSize(14)));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.VipTipBg_Mid, 155 + 72, 288 - 32, this));
            this._vipOpenTips = UICompomentPool.getUICompoment(VipOpenTipsPanel);
            this._vipOpenTips.valueType = VipOpenTipsPanel.numberValue;
            var _loc_1:* = Cache.instance.vip.level;
            var _loc_2:* = VipUtil.getVipMinLevelByType(EVipRecordType._EVipRecordTypeArenaMoney);
            if (_loc_1 < _loc_2)
            {
                this._vipOpenTips.resetLevelTextPos(29 + 3, 1, 29 + 3, 1);
                this._vipOpenTips.resetValueTextPos(96 + 91, 1, 96 + 92, 1);
                this._vipOpenTips.move(207 + 17, 263);
            }
            else
            {
                this._vipOpenTips.resetLevelTextPos(29 + 3, 1, 29 + 3, 1);
                this._vipOpenTips.resetValueTextPos(96 + 91, 1, 96 + 92, 1);
                this._vipOpenTips.move(207 + 17, 263);
            }
            this.addChild(this._vipOpenTips);
            this._vipOpenTips.bgUrl = "";
            this._vipOpenTips.resetTipsTextPos(0, 0, 0, 0);
            this._vipOpenTips.vipType = EVipRecordType._EVipRecordTypeArenaMoney * 10;
            this._rewardItemList = UIFactory.tileList(177, 342 - 29 - 5, 283, 45, this.contentTopOf3DSprite);
            this._rewardItemList.columnWidth = 44;
            this._rewardItemList.rowHeight = 43;
            this._rewardItemList.horizontalGap = 0;
            this._rewardItemList.verticalGap = 0;
            this._rewardItemList.setStyle("skin", new Bitmap());
            this._rewardItemList.setStyle("cellRenderer", TreasureRewardItemCellRenderer);
            this._arenaShop = UIFactory.gButton(Language.getString(41545), 537, 356 - 33, 65, 22, this.contentTopOf3DSprite, "GreenLinkButton");
            this._arenaShop.configEventListener(MouseEvent.CLICK, this.onClickArenaShop);
            this._transferBtn = UIFactory.gLoadingButton(ResFileConst.HeroArenaTransferBtn, 300, 200, 187, 54, this);
            this._transferBtn.configEventListener(MouseEvent.CLICK, this.onTransferHandler);
            this._transferBtn.visible = false;
            this.initItemList();
            return;
        }// end function

        private function initItemList() : void
        {
            var _loc_1:Array = [];
            var _loc_2:* = CopyConfig.instance.getCopyInfoByCode(163);
            if (_loc_2 && _loc_2.rewardShow)
            {
                _loc_1 = _loc_2.rewardShow.split("#");
            }
            var _loc_3:Array = [];
            var _loc_4:int = 0;
            while (_loc_4 < _loc_1.length)
            {
                
                _loc_3.push(new ItemData(int(_loc_1[_loc_4])));
                _loc_4++;
            }
            var _loc_5:* = new DataProvider();
            _loc_5.addItems(_loc_3);
            this._rewardItemList.dataProvider = _loc_5;
            this._rewardItemList.drawNow();
            this._rewardItemList.x = (this.width - this._rewardItemList.columnWidth * this._rewardItemList.length) / 2 + 2;
            return;
        }// end function

        override protected function onClickEnterBtn(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.HeroArenaEnterRestRoom));
            return;
        }// end function

        private function onClickArenaShop(event:MouseEvent) : void
        {
            var _loc_2:* = HeroArenaUtil.getArenaMoneyByLevel(HeroArenaController.HeroArenaLevel).shopIndex;
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallChangeTabIndex, [ShopUtil.ShopTabArena2v2, _loc_2]));
            return;
        }// end function

        public function set type(param1:int) : void
        {
            if (param1 == 1)
            {
                _enterBtn.visible = true;
                this._transferBtn.visible = false;
            }
            if (param1 == 2)
            {
                _enterBtn.visible = false;
                this._transferBtn.visible = true;
            }
            return;
        }// end function

        private function onTransferHandler(event:MouseEvent) : void
        {
            var _loc_4:SPassTo = null;
            var _loc_2:* = new SPassTo();
            _loc_2.mapId = 10100;
            _loc_2.toPoint = new SPoint();
            _loc_2.toPoint.x = 2493;
            _loc_2.toPoint.y = 3374;
            var _loc_3:* = new SPassTo();
            _loc_3.mapId = 10100;
            _loc_3.toPoint = new SPoint();
            _loc_3.toPoint.x = 3078;
            _loc_3.toPoint.y = 3128;
            var _loc_5:* = Math.random() * 10;
            if (_loc_5 < 5)
            {
                _loc_4 = _loc_2;
            }
            else
            {
                _loc_4 = _loc_3;
            }
            AIManager.addFlyBoot(_loc_4);
            AIManager.start();
            if (this._secTimeData == null)
            {
                this._secTimeData = new SecTimerViewData();
            }
            this._secTimeData.setLeftTime(1);
            this._secTimeData.timeOutCaller = this.show;
            this.hide();
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            if (HeroArenaUtil.isNearNpc(1010024) || HeroArenaUtil.isNearNpc(1010025))
            {
                this.type = 1;
            }
            else
            {
                this.type = 2;
            }
            return;
        }// end function

        override protected function updateSize() : void
        {
            super.updateSize();
            if (this._transferBtn)
            {
                this._transferBtn.x = (this.width - 187) / 2;
                this._transferBtn.y = this.height - 23;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._rewardItemList.dispose();
            this._rewardItemList = null;
            this._arenaShop.dispose();
            this._arenaShop = null;
            this._vipOpenTips.dispose();
            this._vipOpenTips = null;
            this._transferBtn.dispose();
            this._transferBtn = null;
            return;
        }// end function

        public static function get instance() : HeroArenaEnterWin
        {
            if (!_instance)
            {
                _instance = new HeroArenaEnterWin;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

        public static function isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
